combobox: Work around popup handler altering model
authorDaniel Boles <dboles@src.gnome.org>
Wed, 18 Jan 2017 22:22:52 +0000 (22:22 +0000)
committerDaniel Boles <dboles@src.gnome.org>
Wed, 18 Jan 2017 22:24:24 +0000 (22:24 +0000)
commite4ede33a650d91804327f052c76322ff06d26a95
tree4c586266cc3e321c8707058ff86548a9f076f21d
parent7a5c995fd4a5da18fafbdecee7cd151766e8b00b
combobox: Work around popup handler altering model

GtkFileChooserButton installs a handler for the popped-up signal, which
refilters the menu, in order to hide the “(None)” item from the popup
if it was previously selected in the ComboBox. This oddity means that:

 • Until recently, this item would be selected in the menu shell, which
   would then be popped up and change the selection away from that item.
   This was therefore redundant (more on which below!) but benign.

 • After the patch for https://bugzilla.gnome.org/show_bug.cgi?id=771242
   however, this causes a critical assertion fail, as now we stash the
   originally selected item in a pointer so that it can be selected only
   after realisation/popup – but by that stage, the model has just been
   refiltered and the previous pointer no longer refers to a valid item.

This commit works around this problem by, after popping up the menu,
getting the active item again, in case a popped-up handler has gone and
invalidated the pointer to the active item that we saved before popup.

If a handler does this, everything done to find/use the original item is
pointless. But this avoids the ugly critical in FileChooserButton, while
not harming every other ComboBox that doesn’t mess with its model while
popping up (hopefully the vast majority), and it’s very difficult to
imagine a way to check if the active item is /going to/ be hidden later)
gtk/gtkcombobox.c